package calendar.commands.event;

import calendar.commands.CalendarCommand;
import calendar.model.CalendarModel;
import calendar.view.panels.EventGridPanel;
import com.google.api.services.calendar.model.Event;
import swing.Dialog;

public class CreateEvent extends CalendarCommand {

    private Event event;

    public CreateEvent(com.google.api.services.calendar.Calendar client) {
        super(client);
    }

    @Override
    protected void protectedExecute() throws Exception {
        final Event result = client.events().insert(calendar.getId(), event).execute();
        Dialog.popup(new EventGridPanel(result));
        CalendarModel.EVENTS.notifyObservers();
    }

    public CreateEvent setEvent(Event event) {
        this.event = event;
        return this;
    }
}
